<template>
  <view  @click="testLogin">
    <!-- 顶部区域 -->
    <view class="top">
      <view class="image-index">
        <image src="https://s2.loli.net/2022/05/07/SDeYpIMQvdPtAG4.png"></image> 
      </view>
      <view class="search-box">
        <user-search @click="gotoSearch"></user-search>
      </view>
    </view>
    <!-- 分割线 -->
    <view class="fengge">
      <image src="https://s2.loli.net/2022/05/07/39duElFsNLrDOYz.png" mode="widthFix"></image>
    </view>
    <!-- 底部分类 -->
    <view class="index">
        <view class="index-item" @click="gotoCate(0)">
          <view class="index-item-text">
            <image src="https://s2.loli.net/2022/05/05/PAlOQUiWh8oTcyb.png" mode=""></image>
            <text>运动</text>
          </view>
        </view>
        <view class="index-item" @click="gotoCate(1)">
          <view class="index-item-text">
            <image src="https://s2.loli.net/2022/05/05/fbgDqN9kpUTSY3l.png" mode=""></image>
            <text>学习</text>
          </view>
        </view>
        <view class="index-item" @click="gotoCate(2)">
          <view class="index-item-text">
            <image src="https://s2.loli.net/2022/05/05/5VUfRudITWj7ow2.png" mode=""></image>
            <text>生活</text>
          </view>
        </view>
      </view>
  </view>
</template>

<script>
  import {mapState,mapMutations} from 'vuex'
  export default {
    data() {
      return {
        
      };
    },
    computed:{
      ...mapState('user_module',['userinfo','isLogin'])
    },
    
    methods: {
      ...mapMutations('user_module',['showLoginInfo']),
      testLogin() {
        if(!this.isLogin) this.showLoginInfo()
      },
      gotoCate(e) {
        if(this.isLogin)
          uni.navigateTo({
            url: '../../subpkg/category/category?id=' + e
          })
      },
      gotoSearch() {
        if(this.isLogin)
        uni.navigateTo({
          url: '../../subpkg/search/search'
        })
      }
    },
    onShow() {
      if(this.isLogin) {
        uni.$setBadge()
        // uni.$tokenTest()
      }
    },
    onLoad() {
      // if(uni.getStorageSync('token')) uni.$tokenTest()
    }
  }
</script>

<style lang="scss">
  //顶部区域
  .top {
    height: 378rpx;
    .image-index {
      display: flex;
      justify-content: center;
      image {
        display: block;
        margin-top: 55px;
        margin-bottom: 8px;
        width: 140rpx;
        height: 140rpx;
        border-radius: 70rpx
      }
    }
    .search-box {
      display: flex;
      justify-content: center;
    }
  }
  //中间分割线
  .fengge {
    display: flex;
    justify-content: center;
  }
  //分类区域
  .index {
      // padding-top: 5rpx;
      margin: 10px 0;
      height: 700rpx;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      .index-item {
        // height: 150rpx;
        margin: 5px 20px;
        border: 1px solid #000000;
        border-radius: 10px;
        // margin-top: 10px;
        // image {
        //   width: 680rpx;
        //   height: 200rpx;
        //   border-radius: 10rpx;
        // }
        .index-item-text {
          display: flex;
          justify-content: center;
          align-items: center;
          padding: 15px 0;
          text {
            font-size: 20px;
            // font-weight: 700;
            color: #000000;
          }
          image {
            display: block;
            width: 90rpx;
            height: 90rpx;
          }
        }
      }
  }
</style>
